package br.com.caelum.mvc.logica;

import java.sql.Connection;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.caelum.contato.DAO.ContatoDAO;
import br.com.caelum.contato.modelo.Contato;

public class RemoveContato implements Logica {

	@Override
	public void executa(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		int id = Integer.parseInt(request.getParameter("id"));
		Contato removeContato = new Contato();
		removeContato.setId(id);
		
		Connection connection = (Connection) request
				.getAttribute("conexao");
		
		ContatoDAO dao = new ContatoDAO(connection);
		dao.remove(removeContato);
		
		RequestDispatcher rd = request.getRequestDispatcher("/lista_contato_elegante.jsp");
		rd.forward(request, response);
		
		System.out.println("Contato Removido com sucesso");
		
		
	}

}
